import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { UiserviceProvider } from '../../providers/uiservice/uiservice';
import { BusiserviceProvider } from '../../providers/busiservice/busiservice';

/**
 * Generated class for the ZwsearchPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-zwsearch',
  templateUrl: 'zwsearch.html',
})
export class ZwsearchPage {
  jobname:any ='';
  gzlx:any='';
  gz:any='';
  sareaList=[];
  sheng:any="";
  shi:any="";
  callback:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,public busi: BusiserviceProvider, private uiservice: UiserviceProvider) {
    this.callback = this.navParams.get("callback");
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ZwsearchPage');
  }
  changearea(){
    if(this.sheng == 'Melaka'){
      this.sareaList = [];
      this.sareaList.push("Batu Berendam");
      this.sareaList.push("Bukit Katil");
      this.sareaList.push("Cheng");
      this.sareaList.push("Krubong");
      this.sareaList.push("Melaka Town");
      this.sareaList.push("Aeon bandaraya");
    }else{
      this.sareaList = [];
    }
  }
  private searchzw() {
    this.uiservice.showLoading();
    this.busi.zwquery(this.jobname,this.gzlx,this.gz,this.sheng,this.shi).subscribe(
      data => {
        this.uiservice.hideLoading();
        if (data._success) {
          if(this.callback){
            this.callback(data.result).then(
              data=>{
                this.navCtrl.pop();
              }
            )
          }
        } else {
          this.uiservice.showAlert(data._message);
        }
      },
      error => {
        this.uiservice.hideLoading();
        this.uiservice.showAlert("Net Error");
      }

    );
  }
}
